<template>
  <van-icon
    color="#777"
    name="star-o"
    :color="value ? '#ffa500' : ''"
    :name="value ? 'star' : 'star-o'"
    @click="onCollect"
  />
</template>

<script>
import { deleteCollect, addCollect } from "@/api/article";
export default {
  props: {
    value: {
      type: Boolean,
      required: true,
    },
    articleId: {
      type: [Number, String, Object],
      required: true,
    },
  },
  methods: {
    async onCollect() {
      try {
        if (this.value) {
          let res = await deleteCollect(this.articleId);

          console.log(res);
          this.$toast("取消收藏成功");
        } else {
          let res = await addCollect(this.articleId);
          console.log(res);
          this.$toast("收藏成功!!");
        }
        this.$emit("input", !this.value);
      } catch (error) {
        this.$toast("操作失败!");
        console.log(error);
      }
    },
  },
};
</script>

<style>
</style>